<?php
	session_start();
	include 'db.php'; //database config and connection	
	$sid = $_SESSION['ses'];
	$id = $_GET['id'];
	$cartId = $_GET['cartId'];
	$qty = $_GET['qty'];
	if(2 > $qty){
		$sql = "DELETE FROM cart WHERE sessionId = '$sid' and cartId='$cartId'";
		mysql_query($sql);
		$order2 = "UPDATE cart_temp SET qty = NULL, deleted = '1' WHERE sessionId = '$sid' and cartId='$cartId'";
		echo "UPDATE cart_temp SET qty = NULL, deleted = '1' WHERE sessionId = '$sid' and cartId='$cartId'";
		mysql_query($order2);
	} else {
		$sql = "update cart set qty = qty - 1 where sessionId = '$sid' and itemId = '$id'";
		mysql_query($sql);
		$order2 = "UPDATE cart_temp SET qty = qty - 1 WHERE sessionId = '$sid' and itemId = '$id'";
		mysql_query($order2);
	}
	
	//header("location:products.php");
?>